/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.Services;


import com.ControlEscolar.Beans.Reticle;
import com.ControlEscolar.DAOs.CurriculumDAO;
import com.ControlEscolar.DAOs.DAOException;
import com.ControlEscolar.DAOs.ReticleDAO;
import com.ControlEscolar.Exceptions.AlreadyExistExp;
import com.ControlEscolar.Exceptions.ServiceExp;
import com.ControlEscolar.Validations.ValidationsReticle;
import java.util.ArrayList;

/**
 *
 * @author Rodna Marrufo Segura
 */
public class ReticleService {
ValidationsReticle validationReticle = new ValidationsReticle();
ReticleDAO reticleDAO = new ReticleDAO();
CurriculumDAO curriculumDAO= new CurriculumDAO();
CurriculumService curriculumService = new CurriculumService();

public void createReticle(ArrayList<String> subjectKey, ArrayList <Integer> semesters,int ID_Curriculum  ) throws DAOException, AlreadyExistExp, ServiceExp{
       try {
            if (isExistReticles(subjectKey, ID_Curriculum)) {
                throw new AlreadyExistExp("YA EXISTE ESE DATO");
            } else {
                for(int index=0; index<subjectKey.size();index++){
                    Reticle reticle=new Reticle(subjectKey.get(index), semesters.get(index), ID_Curriculum);
                    reticleDAO.add(reticle);
                }
            }
        } catch (DAOException ex) {
            throw new ServiceExp();
        }
  }

  private boolean isExistReticles(ArrayList<String> ID_Subjects,int ID_Curriculum) throws DAOException{
      for(int index=0; index<ID_Subjects.size();index++){
                if (validationReticle.isExistReticle(ID_Subjects.get(index), ID_Curriculum)) {
                    return true;
                }
      }
    return false;
  }

  public ArrayList<String> getSubjectsToStudent(int ID_Curriculum, int semester) throws DAOException{
            ArrayList <String> subjectsKeys=new ArrayList();
            ArrayList <Reticle> reticles=reticleDAO.queryStudentReticles(ID_Curriculum, semester);
            for(int index=0; index<reticles.size();index++){
                subjectsKeys.add(reticles.get(index).getSubjectKey());
            }
            return subjectsKeys;
        
  }
}
